#include<bits/stdc++.h>
using namespace std;
struct stu{
	string name;
	int a,b,h;
}s[10000];
int t,tt;
void solve(){
	int n;
	cin >> n;
	string temp1,temp2;
	int maxx = -1,minn = 100000000,aver = 0;
	for(int i = 1;i <= n;i++){
		cin >> s[i].name >> s[i].a >> s[i].b >> s[i].h;
		maxx = max(s[i].a * s[i].b * s[i].h,maxx);
		minn = min(s[i].a * s[i].b * s[i].h,minn);
		aver += s[i].a * s[i].b * s[i].h;
	}
	aver /= n;
	if(maxx == minn){
		cout << "Case " << t - tt << ": no thief\n";
	}else{
		for(int i = 1;i <= n;i++){
			if(s[i].a * s[i].b * s[i].h > aver) {
				temp1 = s[i].name;
			}else if(s[i].a * s[i].b * s[i].h < aver) {
				temp2 = s[i].name;
			}
		}
		cout << "Case " << t - tt << ": " << temp1 << " took chocolate from " << temp2 << "\n";
	}
}
int main(){
	cin >> t;
	tt = t;
	while(tt--) solve();
}